import { defineStore } from 'pinia'

// defineStore 它的类型一般不去指定，直接在配置中写，它会自动去推导出来，你需要进行对state数据配置一下
const useCounterStore = defineStore('counter', {
  // persist: {
  //   key: 'counter',
  //   storage: window.sessionStorage,
  //   paths: ['count']
  // },
  // 当前模块下面的所有的数据都持久化
  persist: true,
  state: () =>
    ({
      count: 100,
      msg: ''
    } as ICounter.State),
  getters: {
    showCount: (state) => state.count + '@'
  },
  actions: {
    incr(n: number) {
      this.count += n
    }
  }
})

export default useCounterStore
